<template>
  <div class="container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-input
          placeholder="请输入内容"
          v-model="search"
          class="input-with-select"
          style="width: 400px"
        >
          <el-button slot="append" icon="el-icon-search" @click="toSearch"></el-button>
        </el-input>
        <!-- <el-button type="primary" size="small" style="float: right">新增</el-button> -->
      </div>
      <div class="text item">
        <el-table :data="tableData" style="width: 100%">
           <el-table-column label="反馈类型" width="160px">
            <template slot-scope="scope">
              <el-tag size="medium">{{ scope.row.feedbackType }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="反馈信息" width="" prop="textarea">
          </el-table-column>
          <el-table-column label="反馈时间" width="">
            <template slot-scope="scope">
              {{ new Date(scope.row.time).toLocaleString() }}
            </template>
          </el-table-column>
          <el-table-column label="处理状态" width="160px">
            <template slot-scope="scope">
              <el-tag size="medium">{{ status[scope.row.status] }}</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="反馈人联系方式" width="" prop="mobile">
          </el-table-column>
          <el-table-column label="处理/驳回 原因" width="" prop="msg">
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button
                size="mini"
                @click="handleEdit(scope.$index, scope.row)"
                >处理</el-button
              >
              <el-button
                size="mini"
                type="danger"
                @click="handleDelete(scope.$index, scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :page-sizes="[10, 20, 50]"
          :page-size="10"
          :current-page.sync="currentPage"
          style="float: right; margin: 20px 0"
          background
          layout="sizes, prev, pager, next"
          :total="10"
        >
        </el-pagination>
        <el-dialog title="修改信息" :visible.sync="dialogFormVisible" :append-to-body='true'>
          <el-form :model="feedbackInfo">
            <el-form-item label="反馈类型" :label-width="formLabelWidth">
              <el-input v-model="feedbackInfo.feedbackType" autocomplete="off" :disabled='true'></el-input>
            </el-form-item>
            <el-form-item label="反馈人联系方式" :label-width="formLabelWidth">
              <el-input v-model="feedbackInfo.mobile" autocomplete="off" :disabled='true'></el-input>
            </el-form-item>
            <el-form-item label="反馈信息" :label-width="formLabelWidth">
              <el-input v-model="feedbackInfo.textarea" autocomplete="off" :disabled='true'></el-input>
            </el-form-item>
            <el-form-item label="反馈时间" :label-width="formLabelWidth">
              <el-input v-model="feedbackTime" :disabled='true' autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="是否处理" :label-width="formLabelWidth">
              <el-select v-model="feedbackInfo.status" placeholder="请选择">
                <el-option label="未处理" :value="0"></el-option>
                <el-option label="已处理" :value='1'></el-option>
                <el-option label="驳回" :value="2"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="处理/驳回 原因" :label-width="formLabelWidth">
              <el-input v-model="feedbackInfo.msg" autocomplete="off"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="updateInfo">确 定</el-button>
          </div>
        </el-dialog>
      </div>
    </el-card>
  </div>
</template>

<script>
import { getFeedback, getFeedbackmohu, updateFeedback, deleteFeedback } from '@/api/feedback'
export default {
  name: '',
  components: {},
  props: {},
  data () {
    return {
      search: '',
      currentPage: 1,
      pageSize: 10,
      total: 100,
      tableData: [],
      status: {
        0: '未处理',
        1: '已处理',
        2: '驳回'
      },
      feedbackTime: '',
      feedbackInfo: {
        feedbackType: '',
        mobile: '',
        textarea: '',
        time: '',
        status: 0,
        msg: ''
      },
      dialogFormVisible: false,
      formLabelWidth: '120px'
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {
    this.getAllInfo()
  },
  methods: {
    handleEdit (index, row) {
      console.log(index, row)
      this.feedbackInfo = row
      this.feedbackTime = new Date(this.feedbackInfo.time).toLocaleString()
      this.dialogFormVisible = true
    },
    handleDelete (index, row) {
      console.log(index, row)
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const res = await deleteFeedback(row)
        console.log(res)
        if (res.data.errno === 1000) {
          this.getAllInfo()
          this.$message({
            type: 'success',
            message: '删除成功!'
          })
        } else {
          this.$message({
            type: 'warning',
            message: '删除失败!'
          })
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    async updateInfo () {
      const res = await updateFeedback(this.feedbackInfo)
      console.log('update res', res)
      if (res.data.errno === 1000) {
        this.$message({
          message: '修改成功',
          type: 'success'
        })
      } else {
        this.$message({
          message: '修改失败',
          type: 'warning'
        })
      }
      this.dialogFormVisible = false
    },
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`)
    },
    handleCurrentChange (val) {
      console.log(`当前页: ${val}`)
    },
    async getAllInfo () {
      const res = await getFeedback()
      console.log('res', res)
      this.tableData = res.data.data
    },
    async toSearch () {
      console.log('this.search', this.search)
      if (this.search) {
        const res = await getFeedbackmohu({
          mobile: this.search
        })
        console.log(res)
        this.tableData = res.data.data
      } else {
        const res = await getFeedback()
        console.log(res)
        this.tableData = res.data.data
      }
    }
  }
}
</script>

<style scoped lang="">
</style>
